<!--
    方案页面 公共插件

    参数：
    op              'add'=新增;'view'=查看;'edit'=修改
    planId          方案ID
    fitScope        方案场景

    方法:
    backInfo        返回结果集
 -->
<template>
    <div>
        <Row>
            <Alert>
                方案基本信息
            </Alert>
        </Row>
        <Form ref="showResultForm" :model="schemeForm" :lable-width="250" :rules="rulesSchemeForm">
            <Row>
                <Col :xs="24" :md="24" :lg="16" :xl="12">
                    <FormItem label="方案编号" prop="planNo" :label-width="100">
                        <Input v-model="schemeForm.planNo" style="width: 250px" :disabled="readonlyNo" maxlength="32"/>
                    </FormItem>
                </Col>
                <Col :xs="24" :md="24" :lg="16" :xl="12">
                    <FormItem label="方案名称" prop="name" :label-width="100">
                        <Input style="width: 250px" v-model="schemeForm.name" :disabled="readonlyName" maxlength="128"/>
                    </FormItem>
                </Col>
            </Row>
        </Form>
        <Row style="text-align: center;">
            <Button @click="save" icon="md-bookmark" type="primary" v-show="op!='view'">保存</Button>
        </Row>
    </div>
</template>
<script>

    import {
        saveRiskPlan,
    } from "@/projects/afs-core-business/api/afs-product/product-plan-select/riskPlan";

    import {
        saveLaunchPlan,
    } from "@/projects/afs-core-business/api/afs-product/product-plan-select/launchPlan";

    import {
        saveFinancePlan,
    } from "@/projects/afs-core-business/api/afs-product/product-plan-select/financePlan";

    import {
        saveDiscountRulePlan,
    } from "@/projects/afs-core-business/api/afs-product/product/discountRulePlan";

    export default {
        components: {},
        props: {
            //状态
            op:{
                type:String,
                required: true,
                default: 'view'
            },
            //方案ID
            planId:{
                type:String,
            },
            //方案场景
            fitScope:{
                type:String,
            },
            //表单
            schemeForm:{
                type:Object,
            },
        },
        data() {
            return {
                //只读
                readonlyNo:true,
                //只读
                readonlyName:true,
                //校验
                rulesSchemeForm: {
                    planNo: [{required: true, message: " 不能为空",trigger: "blur"}],
                    name: [{required: true, message: " 不能为空",trigger: "blur"}],
                },
            };
        },
        methods: {
            //刷新
            refreshCom(){
                console.info("公共部分查询："+this.op);
                if(this.op='add'){
                    this.readonlyNo = false;
                    this.readonlyName = false;
                }
                if(this.op='view'){
                    this.readonlyNo = true;
                    this.readonlyName = true;
                }
                if(this.op='edit'){
                    this.readonlyNo = true;
                    this.readonlyName = false;
                }
            },
            //保存
            save(){
                this.$refs.showResultForm.validate(valid1 => {
                    if(valid1) {
                        let param = this.schemeForm;
                        param.push("fitScope",this.fitScope);
                        param.push("planId",this.planId);

                        //风险定价
                        if(this.fitScope=='005'){
                            saveRiskPlan(param).then(res => {
                                if (res.code === "0000") {
                                    this.schemeForm = res.data;//结果
                                    this.$Message.success("保存成功！");
                                    //编号只读
                                    this.readonlyNo = true;
                                    //返回信息
                                    this.backInfo();
                                }
                            });
                        }
                        //融资校验
                        if(this.fitScope=='006'){
                            saveFinancePlan(param).then(res => {
                                if (res.code === "0000") {
                                    this.schemeForm = res.data;//结果
                                    this.$Message.success("保存成功！");
                                    //编号只读
                                    this.readonlyNo = true;
                                    //返回信息
                                    this.backInfo();
                                }
                            });
                        }
                        //产品投放
                        if(this.fitScope=='004'){
                            saveLaunchPlan(param).then(res => {
                                if (res.code === "0000") {
                                    this.schemeForm = res.data;//结果
                                    this.$Message.success("保存成功！");
                                    //编号只读
                                    this.readonlyNo = true;
                                    //返回信息
                                    this.backInfo();
                                }
                            });
                        }
                        //补贴方案
                        if(this.fitScope=='002'){
                            saveDiscountRulePlan(param).then(res => {
                                if (res.code === "0000") {
                                    this.schemeForm = res.data;//结果
                                    this.$Message.success("保存成功！");
                                    //编号只读
                                    this.readonlyNo = true;
                                    //返回信息
                                    this.backInfo();
                                }
                            });
                        }
                    }
                });
            },
            //返回
            backInfo(){
                this.$emit('backInfo',this.schemeForm);
            },
        },
        mounted() {
        },
        created(){
            this.refreshCom();
        },
    };
</script>
